<?
  include "transactions.php";
  include_once '../includes/constants.php';
  include_once '../includes/functions.php';
  include_once '../includes/session.php';
  include_once '../includes/allstripslashes.php';


  $MERCHANTID	=	$_SESSION['MERCHANTID'];
  $msg			=	trim($_GET['msg']);

  if(empty($_GET['programs'])) {
     $programs	=	trim($_POST['programs']);
     $msg		=	"";
  }
  else
  {
     $programs  = trim($_GET['programs']);
     $msg		= trim($_GET['msg']);

  }
  if($_GET['del']=="del")
  {
      $msg		=	trim($_GET['msg']);
  }


  if (empty($programs))
  {
     $programs	=	"All";
     $link		=	0;

  }
  else
  {
     $link		=	1;
  }
  $sql		=	"SELECT * from partners_program where program_merchantid=$MERCHANTID"; //adding to drop down box
  $result	=	mysql_query($sql);

  switch ($programs)//checking program
      {
       case 'All';    //all pgm
           $sql		=	"SELECT * from partners_joinpgm where joinpgm_merchantid=$MERCHANTID " ;
           $pgmid	=	0;
           $link	=	0;

           $allresult="--";
           $flag	 =	0;

           break;
       default:    //selected pgm

           $sql		=	"SELECT * from partners_joinpgm where joinpgm_programid=$programs";

           $pgmid	=	$programs;

           $_SESSION['PGMID']=$pgmid;

           $sqla	=	"SELECT * FROM  partners_program where program_id='$pgmid'";
           $sqlb	=	"SELECT * FROM  partners_pgmstatus where pgmstatus_programid='$pgmid'";
           $sqlc	=	"SELECT * FROM  partners_secondlevel where secondlevel_programid ='$pgmid'";
           $sqld	=	"select * FROM  partners_firstlevel where firstlevel_programid='$pgmid'";


           $flag	=	1;

           break;
      }

  $total	=	GetPaymentDetails($sql,$currValue,$default_currency_caption); //getting payments (click,sale,lead) values
  $total 	=	explode('~',$total);

  $afftotal	=	GetTotalAffiliates($sql); //getting total affiliates,waiting affiliates,transactions
  $afftotal =	explode('~',$afftotal);

  $totallink=	GetLinks($pgmid,$MERCHANTID);       //getting advertising links
  $totallink=	explode('~',$totallink);


              if($flag==1)
              {
                  $pgmres	=	mysql_query($sqla);
                  $stares	=	mysql_query($sqlb);

                  $secres	=	mysql_query($sqlc);

                  $fstres	=	mysql_query($sqld);

                  while ($pgmrow=mysql_fetch_object($pgmres))
                   {

                     $url                           =	stripslashes(trim($pgmrow->program_url));
                     $description                   =	stripslashes(trim($pgmrow->program_description));
                     $ip                            =	stripslashes(trim($pgmrow->program_ipblocking));
                     $saletype                      =	stripslashes(trim($pgmrow->program_saletype));
                     $status                        =	stripslashes(trim($pgmrow->program_status));
                     $pgmDate						=   stripslashes(trim($pgmrow->program_date));
                     $prgm_fee						= trim($pgmrow->program_fee);
                     $prgm_value					= $pgmrow->program_value;
                     $prgm_type						= $pgmrow->program_type;
                     $prgm_avail					= $pgmrow->program_countries;
                   }

                     while ($starow=mysql_fetch_object($stares))
                   {


                       $stclick                       =	stripslashes(trim($starow->pgmstatus_clickapproval));
                       $stlead                        =	stripslashes(trim($starow->pgmstatus_leadapproval));
                       $stsale                        =	stripslashes(trim($starow->pgmstatus_saleapproval));

                       $stmailaffiliate               =	stripslashes(trim($starow->pgmstatus_mailaffiliate));
                       $stmailmerchant                =	stripslashes(trim($starow->pgmstatus_mailmerchant));
                       $staffiliateapproval           =	stripslashes(trim($starow->pgmstatus_affiliateapproval));

                       //modified by SMA on 22-Feb-06
                        $impression_approval   =  stripslashes(trim($starow->pgmstatus_impressionapproval));
                        $impression_mail       =  stripslashes(trim($starow->pgmstatus_impressionmail));
                       //End modify

                     }

                      while ($fstrow=mysql_fetch_object($fstres))
                   {

                       //    firstlevel_salerate

                        $click                    =	stripslashes(trim($fstrow->firstlevel_clickrate));
                        $lead                     =	stripslashes(trim($fstrow->firstlevel_leadrate));
                        $sale                     =	stripslashes(trim($fstrow->firstlevel_salerate));
                        $saletype                 =	stripslashes(trim($fstrow->firstlevel_saletype));
						
                        //modified by SMA 17-JUNE-06
                        $impression_rate   =  stripslashes(trim($fstrow->firstlevel_impressionrate));
                        $impression_unit   =  stripslashes(trim($fstrow->firstlevel_unitimpression));
						
						//Modified for Recurring Commission
						$recur_sale			= stripslashes(trim($fstrow->firstlevel_recur_sale));
						$recur_percentage	= stripslashes(trim($fstrow->firstlevel_recur_percentage));
						$recur_period		= stripslashes(trim($fstrow->firstlevel_recur_period));
                        //End modify
						

                         if($currValue != $default_currency_caption ){
	                		$click     =   getCurrencyValue($pgmDate, $currValue, $click);
	                		$lead      =   getCurrencyValue($pgmDate, $currValue, $lead);
							 $impression_rate   =   getCurrencyValue($pgmDate, $currValue, $impression_rate);
                            if($saletype!="%") {
                            	$sale     =   getCurrencyValue($pgmDate, $currValue, $sale);
                                $saletype =  $currSymbol;
                                }
	           			}
                   }
                      while ($secrow=mysql_fetch_object($secres))
                   {
                        //$sclick                    =$secrow->secondlevel_clickrate;
                        //$slead                     =$secrow->secondlevel_leadrate;
                        $ssale                     =stripslashes(trim($secrow->secondlevel_salerate));
                        $st                        =stripslashes(trim($secrow->secondlevel_saletype));    /// error

                         if($currValue != $default_currency_caption ){

                            if($st!="%")
                            	$ssale     =   getCurrencyValue($pgmDate, $currValue, $ssale);
                                $st		   =  $currSymbol;
	           			}

                    }



              } // closing


    //////////////////////// program fee and type /////////////////////
   if(($prgm_type == "0")){
   					 $prgm_fee						= $program_fee;
                     $prgm_value					= $program_value;
                     $prgm_type						= $program_type;
   }
///////////////////////////////////////////////////////////////////
  $today        = date("Y-m-d");
  if($prgm_fee)
  {
  	if($currValue != $default_currency_caption ) $prgm_fee  =	getCurrencyValue($today, $currValue, $prgm_fee);
  }
  ?>

<table border="0"  cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="98%" class="tablewbdr">
  <tbody>
  <tr>
    <td align="center" height="1"><a  href="index.php?Act=newprogram">
    <strong><?= $lpgm_CREATEPROGRAME ?></strong></a></td>
    </tr>

    <tr>
    <td align="center" height="1"><? echo "<p align='center' > <span class='textred'>$msg</span></p>";?></td>
    </tr>

    </tbody></table>


<form name="Getprogram" method="post" action="">

<input name="policybtn" type="hidden" value="1" />
<input name="aprdays" type="hidden" value="0" />
<input name="PID" type="hidden" />
<input name="adtype" type="hidden" />
<input name="adID" type="hidden" />
<input name="proID" type="hidden" value="98" />
<table align="center" border="0" cellpadding="0" cellspacing="0" width="80%">
  <tbody>
  <tr>
    <td valign="top" width="60%">
      <table align="center" bgcolor="#000000" border="0" cellpadding="1" cellspacing="0" width="100%">
        <tbody>
        <tr>
          <td>
	            <table bgcolor="#ffffff" border="0" cellpadding="5" cellspacing="0" width="100%" style="border-collapse: collapse"  class="tablebdr" >
	            <tbody>
              <tr bgcolor="#ffcc33">
                <td width="495" bgcolor="#ffffff" class="tdhead"><b><?=$lpgm_AffiliateProgram?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </b>
    <select name="programs" onchange="document.Getprogram.submit()"><option value="All" ><?=$lpgm_AllPrograms?></option>
                               <?  while($row=mysql_fetch_object($result))

                               {
                               if($programs=="$row->program_id")
                                      $programName="selected = 'selected'";
                               else
                                $programName="";

                               ?>
                                 <option <?=$programName?> value="<?=$row->program_id?>"><?=$common_id?>:<?=$row->program_id?>...<?=stripslashes($row->program_url)?> </option>
                               <?
                               }
                               ?>
    </select>&nbsp;&nbsp;&nbsp;</td>
                <td align="right" width="209" bgcolor="#ffffff" class="tdhead">

                <?
                                        if($link==1)
                         {
                 ?>
                <span class='textred'><?=$lang_Status?> : <?=ucwords($status)?></span><br/><a href='index.php?Act=programedit&amp;mode=edit&amp;id=<?=$pgmid?>'> <?=$lpgm_Edit?> &raquo;</a> <br/> <a href="index.php?Act=uploadProducts&amp;pgmid=<?=$pgmid?>"><?=$lang_upload_prd?></a>&raquo;

                <?php
                    }
                                ?>

                         <?
                                        if($link==1)
                         {
                 ?>
                <br/><a href='pgmdelete.php?id=<?=$pgmid?>' id="del"  onclick="return del_onclick()"><?=$lpgm_Delete?></a>&raquo;

                <?php
                    }
                                ?>

               </td>
			   </tr>
              <tr>
                <td colspan="2"  height="459">
                  <table border="0" cellpadding="2" cellspacing="0" width="100%"  style="border-collapse: collapse"  bgcolor="#ffffff" class="tablewbdr">
                    <tbody>
                    <tr>
                      <td  height="45" width="50%" class="grid1" align="left">
                        <div align="left"><b><a href="index.php?Act=listaffiliate&amp;pgmid=<?=$pgmid?>"><?=$lpgm_RegisteredAffiliates?>&nbsp; -<?=$afftotal[0]?></a></b></div></td>
                      <td  height="45" width="50%" class="grid1" align="right">
                        <b><a href="index.php?Act=waitingaff&amp;pgmid=<?=$pgmid?>"><?=$lpgm_WaitingAffiliates?> -<?=$afftotal[1]?> </a></b></td>
                      </tr>

                    <tr>
                      <td bgcolor="#ffffff" colspan="2" height="45">
                        <div align="center"><b><?=$lpgm_ProgramURL?></b><br/>
                          <?=$url?></div><br/></td></tr>
                    <tr>
                      <td align="center" colspan="2" height="15" class="grid1">
                        <div align="center"><b><?=$lpgm_Description?></b><br/></div>
                        </td></tr>
                    <tr>
                      <td align="center"  colspan="2" height="81" class="grid1">
                        <textarea rows="4" name="S1" cols="51"><?=$description?></textarea></td>
                    </tr>
                    <tr>
                      <td colspan="2" height="81" align="center">

						<!--Commission Table-->
                        <table border="0" cellpadding="2" cellspacing="0" width="100%" class="tablewbdr" style="border-collapse: collapse" >
                          <tbody>
                          <tr >
                            <td align="center" bgcolor="#FFFFFF" colspan="4"><strong><?=$lpgm_Commissions?></strong></td>
                            </tr>
                          <tr >
                            <td align="center" bgcolor="#FFFFFF" colspan="4">&nbsp;</td>
                            </tr>
                          <tr >
                            <td align="center" bgcolor="#FFFFFF" class="tdhead"><?=$lpgm_Type?></td>
                            <td align="center" bgcolor="#FFFFFF" class="tdhead"><?=$lpgm_Commissions?></td>
                            <td align="center" bgcolor="#FFFFFF" class="tdhead"><?=$lpgm_Approval?></td>
                            <td align="center" bgcolor="#FFFFFF" class="tdhead"><?=$lpgm_IPBlocking?></td>
						</tr>
                          <!-- Modified by SMA 15-JUNE-06  -->
                          <tr>
                            <td align="left" ><img
                               alt="" border='0' height="10" src="../images/impression.gif" width="10" />&nbsp;-&nbsp;
                              <?=$lpgm_Impression?></td>
                            <td align="center" ><?=$currSymbol.$impression_rate?></td>
                            <td align="center" ><?=$impression_approval?></td>
                            <td align="center" >&nbsp;</td></tr>
                           <!-- End Modify  -->
						
                          <tr>
                            <td class="grid1" align="left"><img border="0" height="10"
                              src="../images/click.gif"
                              width="10" alt="" />- <?=$lpgm_click?></td>
                            <td align="center"  class="grid1"><?=$currSymbol.$click?></td>
                            <td align="center"  class="grid1"><?=$stclick?></td>
                            <td align="center"  class="grid1"><?=$ip?><?=$lpgm_minutes?></td></tr>
                          <tr>
                            <td  align="left"><img border="0" height="10"
                              src="../images/lead.gif"
                              width="10" alt="" /> - <?=$lpgm_lead?></td>
                            <td align="center" ><?=$currSymbol.$lead?></td>
                            <td align="center" ><?=$stlead?></td>
                            <td >&nbsp;</td></tr>
                          <tr>
                            <td  class="grid1" align="left"><img border="0" height="10"
                              src="../images/sale.gif"
                              width="10" alt="" /> - <?=$lpgm_sale?></td>
                            <td align="center"  class="grid1"><?=$saletype?><?=$sale?></td>
                            <td align="center"  class="grid1"><?=$stsale?></td>
                            <td align="center"
                           class="grid1">&nbsp;</td></tr>
                          <tr>
                            <td  colspan="4">&nbsp;
                            </td>
                          </tr>
						  
				<!-- Added by SMA on 20-JUNE-2006 for Recurring Commision -->
						<tr>
                            <td  colspan="4" class="tdhead" align="center">
                            <b><?=$recur_commission_head?></b></td>
                        </tr>
                        <tr>
                            <td colspan="4">
                            </td>
                        </tr>
						<tr>
							<td colspan="4" align="left">
								<? if($recur_sale == '1') { ?>
								<?=$recur_sale_head?>&nbsp;<?=$recur_percentage?>&nbsp;<?=$recur_percent_month_head?>&nbsp;<?=$recur_period?>&nbsp;<?=$recur_months_head?>
								<? } else { echo $recur_no_msg; } ?>
							</td>
						</tr>
                        <tr>
                            <td colspan="4">
                            </td>
                        </tr>
				<!-- End Added by SMA on 20-JUNE-2006 -->
							
                          <tr>
                            <td  colspan="4" class="tdhead" align="center">
                            <b><?=$lpgm_SecondTireCommission?></b></td>
                            </tr>
                          <tr>
                            <td colspan="4">
                            </td>
                            </tr>
                          <tr>
                            <td  class="grid1">

                            <img border="0" height="10"
                              src="../images/sale.gif"
                              width="10" alt="" /> - <?=$lpgm_sale?></td>
                            <td align="center"  class="grid1"><?=$st?><?=$ssale?> </td>


                            <td align="center"  class="grid1">
                            <?


                            if(!$programs=="All")
                            {
                              if(mysql_num_rows($secres)<1)

                                 {
                            ?>
                             <?=$lpgm_NoSecondTyreCommissionOffered?>

                            <?

                                }

                             }

                             ?> &nbsp;</td>
                            <td align="center"
                           class="grid1">&nbsp;</td></tr>
                     <?

                     if(($programs != "All") and ($prgm_fee)){?>
                      <tr>
                            <td  colspan="4">&nbsp;
                            </td>
                            </tr>
                          <tr>
                            <td  colspan="4" class="tdhead" align="center">
                            <?=$lpgm_programfees?></td>
                            </tr>
                          <tr>
                            <td  colspan="4">
                            </td>
                            </tr>

                     <tr>
                            <td  class="grid1">
                            <?=$lpgm_programfees?> </td>
                            <td align="center"  class="grid1"></td>
                            <td align="center"  class="grid1">
                             		  <?php echo $currSymbol.$prgm_fee?>
                           </td>
                            <td align="center"
                           class="grid1">&nbsp;</td>
                       </tr>
                        <tr>
                            <td  class="grid1">
                            <?=$lpgm_programtype?> </td>
                            <td align="center"  class="grid1"></td>
                            <td align="center"  class="grid1">
                             		  <?php
                                      if($prgm_type==2){
                                        echo "Recurring ( $prgm_value) ";


                                      }else echo "One-Time";

                                      ?>
                           </td>
                            <td align="center"
                           class="grid1">&nbsp;</td></tr> <?}?>

                          </tbody></table>
						<!--Commission Table-->

						</td></tr>
                    <tr>
                      <td  colspan="2" height="12">&nbsp;
                        </td></tr>
                    <tr>
                      <td  colspan="2" height="12" class="tdhead" align="center">
                        <?=$lpgm_EmailandProgramSettings?>
						</td></tr>
                    <tr>
                      <td  colspan="2" height="12" align="center">
                      </td>
					</tr>
                    <tr>
                      <td colspan="2" height="22">

						<!--Email Program Settings-->
						  <table border="0" cellpadding="2" cellspacing="0" width="608" class="tablewbdr" style="border-collapse: collapse"  >
                          <tbody>
                          <tr>
                            <td  class="2text" height="26"
                              width="358" align="left">
                            <?=$lpgm_Sendemailtoaffiliatewhentransactionappears?>:</td>
                            <td  class="2text" height="26"
                              width="242" align="left">
                              <?=$stmailaffiliate?>
                            </td></tr>
                          <tr>
                            <td  class="2text" height="28"
                              width="358">
                            <?=$lpgm_Sendemailtomewhentransactionappears?></td>
                            <td  class="2text" height="28"
                              width="242"><?=$stmailmerchant?></td></tr>
                          <tr>
                            <td  class="2text" height="19"
                              width="358">
                            <?=$lpgm_AffiliateApproval?></td>
                            <td  class="2text" height="19"
                              width="242"><?=$staffiliateapproval?></td>
                          </tr>
                          <tr>
                            <td  class="2text" height="19"
                              width="358">
                            <?=$lpgm_OfferAvailable?></td>
                            <td  class="2text" height="19"
                              width="242"><?=ucwords(strtolower(str_replace(",",", ",$prgm_avail)))?></td>
                          </tr>
						</tbody>
						</table>
						<!--Email Program Settings-->

					  </td>
					</tr>
					<tr>
						<td height="57" colspan="2">
						<table border="0" cellpadding="2" cellspacing="0" width="608"  class="tablewbdr" style="border-collapse: collapse" >
						  <tbody>
						  <tr>
							<td  height="15" align="center">
							  &nbsp;
										<!--Advertising Links-->
<table border="0" cellpadding="0"  width="100%" class="tablewbdr" style="border-collapse: collapse"  cellspacing="0" align="center">
      <tr>
        <td width="25%" class="tdhead" align="center" colspan="5"><?=$lpgm_AdvertisingLinks?></td>
      </tr>
<?php
	if($link==1)
	{    /////////// checkin it is not for all program
		$tot=$totallink[0]+$totallink[1]+$totallink[2]+$totallink[3]+$totallink[4];

		if($tot==0)
		{
?>
		 <tr>
         <td width="20%" align="center" class="textred"  colspan="5"  height="20">
		 <?=$lpgm_NoLinksAddedtoThisProgram?><br/>
		 <a href="index.php?Act=addlinks" ><?=$lpgm_ClickHereToAddLinks?></a></td>
         </tr>
<?php
		}
		else
		{
?>
		<tr>
        <td width="20%" align="center" class="grid1" ><a href="index.php?Act=add_text"><?=$lpgm_Text?> - <?=$totallink[1]?></a></td>
        <td width="20%" align="center" class="grid1"  ><a href="index.php?Act=add_html"><?=$lpgm_HTML?> - <?=$totallink[4]?></a></td>
        <td width="20%" align="center" class="grid1" ><a href="index.php?Act=add_banner"><?=$lpgm_Banner?> -<?=$totallink[0]?></a></td>
        <td width="20%" align="center" class="grid1" ><a href="index.php?Act=add_popup"><?=$lpgm_Popup?> - <?=$totallink[2]?></a></td>
        <td width="20%" align="center" class="grid1" ><a href="index.php?Act=add_flash"><?=$lpgm_Flash?> - <?=$totallink[3]?></a></td>
		</tr>
<?
		}  //// else close
	}    // if link close
?>

   </table>
										<!--Advertising Links-->
							  </td></tr>
						  </tbody>
						  </table>

                      </td></tr>
                    </tbody></table>
				  </td></tr></tbody></table>
				</td></tr></tbody></table>
					</td></tr></tbody></table>
					&nbsp;</form>
  <script language="javascript" type="text/javascript">

<!--

function del_onclick() {
if(confirm("<?=$lpgm_DoyouWanttoDeleteThisProgram?>"))
        {
                return true;
        }
        else
        {
        return false;
        }

}

//-->
</script>